package com.xiaohudie.JUC;

/**
 * @Author xiao hu die
 * @Date 2022/1/15 15:00
 * @Version 1.0
 */

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**循环栅栏*/
public class Thread09 {
    private static Integer number =7;
    public static void main(String[] args) {
     /**新建一个循环栈栏对象*/
        CyclicBarrier cyclicBarrier =new CyclicBarrier(number,()->{
            System.out.println("可以召唤神龙了");
        });
        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                System.out.println("收集到了一颗龙蛋");
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            },String.valueOf(i)).start();
        }
        System.out.println(Thread.currentThread().getName()+"******************");
    }
}
